package com.yixq.util;

import java.io.OutputStream;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Workbook;

public class ResponseUtil {
	/**
	 * 把数据写到jsp页面上
	 * 
	 * @param response
	 * @param o
	 * @throws Exception
	 */

	public static void write(HttpServletResponse response, Object o)
			throws Exception {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.print(o.toString());
		out.flush();
		out.close();
	}

	/**
	 * 把数据写入到excel
	 * 
	 * @param response
	 * @param wb
	 * @param fileName
	 * @throws Exception
	 */
	public static void export(HttpServletResponse response, Workbook wb,
			String fileName) throws Exception {
		// 固定格式
		response.setHeader("Content-Disposition", "attachment;filename="+ new String(fileName.getBytes("utf-8"), "iso8859-1"));
		response.setContentType("application/ynd.ms-excel;charset=UTF-8");
		OutputStream out = response.getOutputStream();// 输出流
		wb.write(out);
		out.flush();
		out.close();
	}

}
